<template>
  <div  style="padding: 15px;">
    <vxe-toolbar id="warehouseLocationId" :custom="{storage: true}" export :refresh="{query: findList}">
      <template v-slot:buttons>
        <el-button @click="findList">查询</el-button>
      </template>
    </vxe-toolbar>
    <vxe-table
      ref="xTable"
      border
      resizable
      stripe
      highlight-current-row
      :align="allAlign"
      show-footer
      highlight-hover-row
      row-id="id"
      :export-config='{type:"csv"}'
      class="mytable-footer"
      height="700"
       :loading="loading"
      :data="tableData"
      :edit-config="{trigger: 'click', mode: 'row', showStatus: true}"
      sort-config.remote
      @sort-change="sortList"
    >
      <vxe-table-column type="checkbox" width="60"></vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="warehouseCode" title="仓库" min-width="200" show-header-overflow show-overflow/>
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.warehouseCode" placeholder="请输入仓库" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="warehouseSpaceCode" title="库区" min-width="200" />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.warehouseSpaceCode" placeholder="请输入库区" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="location" title="库位" min-width="200" />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.locationName" placeholder="请输入库位" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="goodsName" title="商品名称" min-width="150" sortable />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.goodsName" placeholder="请输入商品名称" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="goodCode" title="商品编码" min-width="150" sortable />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.goodCode" placeholder="请输入商品编码" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="goodsBarCode" title="商品条码" min-width="150" sortable />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.goodsBarCode" placeholder="请输入商品条码" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="containerBarCode"
          title="容器号"
          min-width="150"
          sortable
        />
        <template v-slot:header="{ column }">
          <el-input
            v-model="listQuery.containerBarCode"
            placeholder="请输入容器号"
            clearable
          />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="expirationQuantity" title="保质期天数" min-width="150" sortable />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.expirationQuantity" placeholder="请输入保质期天数" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="gmtManufacture" title="生产日期" min-width="400" sortable show-header-overflow show-overflow />
        <template v-slot:header="{ column }">
<!--          <el-date-picker-->
<!--            v-model="listQuery.gmtDocumentation"-->
<!--            value-format="yyyy-MM-dd HH:mm:ss"-->
<!--            format="yyyy-MM-dd"-->
<!--            type="date"-->
<!--            style="width: 100%"-->
<!--            :picker-options="pickerOptions"-->
<!--            placeholder="选择日期">-->
<!--          </el-date-picker>-->

          <el-date-picker
            v-model="listQuery.gmtManufactureRange"
            type="daterange"
            value-format="yyyy-MM-dd"
            :picker-options="pickerOptions"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            style="width:100%"

            @change="value => changeDate(value, 'gmtManufacture')"
          />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="gmtExpire" title="过期日期" min-width="150" sortable show-header-overflow show-overflow />
        <template v-slot:header="{ column }">
          <el-date-picker
            v-model="listQuery.gmtDocumentation"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd"
            type="date"
            style="width: 100%"
            :picker-options="pickerOptions"
            placeholder="选择日期">
          </el-date-picker>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="gmtStock" title="存货日期" min-width="150" sortable show-header-overflow show-overflow />
        <template v-slot:header="{ column }">
          <el-date-picker
            v-model="listQuery.gmtDocumentation"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd"
            type="date"
            style="width: 100%"
            :picker-options="pickerOptions"
            placeholder="选择日期">
          </el-date-picker>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="lot" title="入库批次" min-width="150" sortable />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.lot" placeholder="请输入入库批次" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="goodsStatusName" title="库存状态" min-width="150" sortable />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.goodsStatusName" placeholder="请输入库存状态" clearable />
        </template>
      </vxe-table-column>

      <vxe-table-column>
        <vxe-table-column field="isLock" title="锁定状态" min-width="150" sortable />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.isLock" placeholder="请输入锁定状态" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="goodsUnit" title="基本单位" min-width="100" sortable fixed="right"/>
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.goodsUnit" placeholder="请输入基本单位" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="quantity" title="库存数量" min-width="100" sortable fixed="right"/>
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.quantity" placeholder="请输入库存数量" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="modifiedBy" title="可用数量" min-width="100" sortable fixed="right"/>
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.modifiedBy" placeholder="请输入可用数量" clearable />
        </template>
      </vxe-table-column>


      <vxe-table-column title="操作" fixed="right" min-width="150">
        <template slot-scope="scope">
          <!-- <el-tooltip  effect="dark" content="详情" placement="top">
            <vxe-button type="text" @click="funcDetail(scope.row.code)">
              <i class="el-icon-document" />
            </vxe-button>
          </el-tooltip>
          <el-tooltip  effect="dark" content="编辑" placement="top">
            <vxe-button type="text" @click="funcEdit(scope.row.code)">
              <i class="el-icon-edit" />
            </vxe-button>
          </el-tooltip>
          <el-tooltip  effect="dark" content="删除" placement="top">
            <vxe-button type="text" @click="funcDelete(scope.row.code)">
              <i class="el-icon-delete" />
            </vxe-button>
          </el-tooltip> -->

        </template>
      </vxe-table-column>
    </vxe-table>
    <vxe-pager
      :loading="loading"
      :current-page.sync="listQuery.pageNum"
      :page-size.sync="listQuery.pageSize"
      :total="listQuery.total"
      :layouts="['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total']"
      @page-change="handlePageChange"
    />
    <!-- <vxe-modal v-model="modelAddFlag" title="新增" width="600" height="700" resize>
      <compAdd ref="addRef" @fatherAddMethod="fatherAdd" @fatherCancelMethod="fatherCancel" />
    </vxe-modal>
    <vxe-modal v-model="modelEditFlag" title="编辑" width="600" height="700" resize>
      <compEdit ref="editRef" @fatherEditMethod="fatherEdit" @fatherCancelMethod="fatherCancel" />
    </vxe-modal>
    <vxe-modal v-model="modelDetailFlag" title="详情" width="600" height="700" resize>
      <compDetail ref="detailRef" />
    </vxe-modal> -->
  </div>
</template>
<script>
import Vue from 'vue'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
import XEUtils from 'xe-utils'
import VXEUtils from 'vxe-utils'
Vue.use(VXETable, VXEUtils, XEUtils, { mounts: ['cookie'] })
// import compAdd from './components/brandAdd.vue'
// import compEdit from './components/brandEdit.vue'
// import compDetail from './components/brandDetail.vue'
import request from '@/utils/request'
import { inventoryList} from '@/api/store'
export default {
  name: 'Parent',
  components: {
  },
  data() {
    return {
      message: '',
      // 日期选项
      // pickerOptions: {
      //     disabledDate(time) {
      //       return time.getTime() > Date.now();
      //     },
      //     shortcuts: [{
      //       text: '今天',
      //       onClick(picker) {
      //         picker.$emit('pick', new Date());
      //       }
      //     }, {
      //       text: '昨天',
      //       onClick(picker) {
      //         const date = new Date();
      //         date.setTime(date.getTime() - 3600 * 1000 * 24);
      //         picker.$emit('pick', date);
      //       }
      //     }, {
      //       text: '一周前',
      //       onClick(picker) {
      //         const date = new Date();
      //         date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
      //         picker.$emit('pick', date);
      //       }
      //     }]
      //   },
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      loading: false,
      allAlign: 'center',
      tableData: [],
      modelAddFlag: false,
      modelbindingFlag:false,
      modelEditFlag: false,
      modelDetailFlag: false,
      copy: false,
      listQuery: {
        total: 0,             //总数
        createdBy:'',         //创建人
        modifiedBy:'',        //修改人
        gmtCreated:'',        //创建时间
        gmtModified:'',       //修改时间
        code:'',                                              //数据标识 ,
        gmtExpire:'',                                         //过期日期 ,
        gmtManufacture:'',                                    //生产日期 ,
        gmtStock:'',                                          //存货日期 ,
        goodsBarCode:'',                                      //商品条码 ,
        goodsCode:'',                                         //商品 ,
        goodsName:'',                                         //商品名称 ,
        goodsUnit:'',                                         //单位 ,
        isLock:'',                                            //锁定状态 ,
        location:'',                                          //库位 ,
        lotId:'',                                             //批次号 ,
        quantity:'',                                          //数量 ,
        remarks:'',                                           //备注 ,
        shipmentCode:'',                                      //入驻商 ,
        useQuantity:'',                                       //占用数量 ,
        warehouseCode:'',                                     //仓库 ,
        warehouseSpaceCode:'',                                //库区
        pageNum: 1,
        pageSize: 10,
        sortField: '',
        sortType: '',
      },
    }
  },
  created() {
    this.findList()
  },
  methods: {
    changeDate(value, prefix) {
      if (value) {
        this.listQuery[`${prefix}Start`] = value[0];
        this.listQuery[`${prefix}End`] = value[1];
      } else {
        this.listQuery[`${prefix}Start`] = "";
        this.listQuery[`${prefix}End`] = "";
      }
    },
    //获取列表
    findList() {
      this.loading = true
      return inventoryList(this.listQuery).then(response => {
        this.tableData = response.data.records
        this.listQuery.total = response.data.total
        this.loading = false
      })
    },
    // 排序
    sortList({ column, property, order }) {
      if (order) {
        this.listQuery.sortField = property
        this.listQuery.sortType = order
      } else {
        this.listQuery.sortField = ''
      }
      this.findList()
    },
    // 添加方法
    funcAdd() {
      // this.$refs.addRef.reset();    //重置
      this.modelAddFlag = true
    },
    // 修改方法
    funcEdit(code) {
      this.$refs.editRef.getInfo(code)
      this.modelEditFlag = true
    },
    // 详情方法
    funcDetail(code) {
      this.$refs.detailRef.getInfo(code)
      this.modelDetailFlag = true
    },
    // 删除方法
    funcDelete(row) {
      this.$confirm('确认删除吗？').then(_ => {
        brandDelete(row).then(response => {
          this.$message({ message: response.msg, type: 'success' })
          this.findList()
        })
      }).catch(_ => {})
    },
    // 增加组件的父方法
    fatherAdd() {
      this.modelAddFlag = false
      this.findList()
    },
    // 编辑组件的父方法
    fatherEdit() {
      this.modelEditFlag = false
      this.findList()
    },
    // 公共取消
    fatherCancel(modelFlag) {
      switch (modelFlag) {
        case 'add':
          this.modelAddFlag = false
          break
        case 'edit':
          this.modelEditFlag = false
          break
        case 'detail':
          this.modelDetailFlag = false
          break
        default:
      }
    },
    // 分页handle
    handlePageChange({ currentPage, pageSize }) {
      this.listQuery.pageNum = currentPage
      this.listQuery.pageSize = pageSize
      this.findList()
    },
    // 底部颜色设置
   /*  footerCellClassName({ $rowIndex, column, columnIndex }) {
      if (columnIndex === 0) {
        if ($rowIndex === 0) {
          return 'col-blue'
        } else {
          return 'col-red'
        }
      }
    }, */
    // 设置底部合计
    footerMethod({ columns, data }) {
      return [
        columns.map((column, columnIndex) => {
          if (columnIndex === 0) {
            return '合计'
          }
          if (['pageviews', 'forecast'].includes(column.property)) {
            return XEUtils.sum(data, column.property)
          }
          return null
        })
      ]
    }
  }
}
</script>

<style>
.vxe-table .vxe-body--column:not(.col--ellipsis), .vxe-table .vxe-footer--column:not(.col--ellipsis), .vxe-table .vxe-header--column:not(.col--ellipsis) {
 padding: 6px 0;
}
.vxe-toolbar{padding:0 0 10px 0}
</style>
